layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form,
    layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    //用于同步编辑器内容到textarea
    layedit.sync(editIndex);
    
    form.on("submit(addEmailTemplate)",function(data){
        var content = layedit.getContent(editIndex);
        $("#content").val(content);

        var options = {
            dataType: "json",
            success: function (data) {
                if(data && data.code==0){
                    layer.msg("添加邮件模板成功~",{icon:6});
                    setTimeout(function(){
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    },500);
                }else{
                    layer.msg(data.msg?data.msg:"创建失败~",{icon:5});
                }

            },
            error: function (data) {
                layer.msg(data.msg?data.msg:"创建失败~");
            }
        };
        $("#listForm").ajaxSubmit(options);
    })

    //创建一个编辑器
    layedit.set({
        uploadImage: {
            url: '/up/lay2' //接口url
            , type: 'post' //默认post
        }
    });
    var editIndex = layedit.build('contents',{
        height : 535

    });

})